<template>
  <div class="container-content">
    <!-- <el-row>
          <el-col :span="24">
              <h3 class="panel-title">新建客户</h3>
          </el-col>
      </el-row> -->
    <el-form
      ref="formObjectRef"
      :model="formObject"
      label-width="100px"
      :rules="formObjectRules"
      status-icon
      label-position="left"
    >
      <el-dropdown
        style="position: absolute; right: 50px; top: 20px; z-index: 10"
        trigger="click"
        @command="handleCommand"
      >
        <el-button size="small" type="primary">
          选单<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="procurementContract"
            >采购合同</el-dropdown-item
          >
          <el-dropdown-item command="purchaseRequisition "
            >采购申请单</el-dropdown-item
          >
          <el-dropdown-item command="salesOrder">销售订单</el-dropdown-item>
          <el-dropdown-item command="inquirySheet ">询价单</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <el-collapse v-model="activeName" @change="handleClick">
        <el-collapse-item title="基本信息" name="basic">
          <div class="desc-title">基本信息</div>
          <el-row :gutter="20">
            <el-col v-if="rowId" :span="8">
              <el-form-item label="单据类型" prop="docType">
                <el-input
                  :disabled="true"
                  style="width: 100%"
                  v-model="formObject.docType"
                  :props="props"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col v-if="!rowId" :span="8">
              <el-form-item label="单据类型" prop="docType">
                <el-cascader
                  style="width: 100%"
                  v-model="formObject.docType"
                  :props="props"
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="单据编号" prop="documentCode">
                <el-input v-model="formObject.documentCode"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="供应商" prop="supplierId">
                <el-input v-model="formObject.supplierId">
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('supplierId')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="采购员" prop="applyId">
                <el-input v-model="formObject.applyId"></el-input>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="8">
              <el-form-item label="业务类型" prop="docBusinessType">
                <el-input :disabled="true" v-model="docBusinessType"></el-input>
              </el-form-item>
            </el-col> -->
            <el-col :span="8">
              <el-form-item label="采购组织" prop="purchaseOrgLabel">
                <el-input v-model="formObject.purchaseOrgLabel">
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-notebook-2"
                    style="cursor: pointer"
                    @click="addDialog('deptId')"
                  ></i>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <!-- <el-col :span="8">
                            <el-form-item
                                label="单据状态"
                                prop="companyWebsite"
                            >
                                <el-input
                                    v-model="formObject.companyWebsite"
                                ></el-input>
                            </el-form-item>
                        </el-col> -->

              <el-form-item label="采购部门" prop="purchaseDept">
                <el-input v-model="formObject.purchaseDept"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="采购日期" prop="applyTime">
                <el-date-picker
                  v-model="formObject.applyTime"
                  type="datetime"
                  placeholder="请选择采购日期"
                  style="width: 100%"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="采购组" prop="purchaseGroup">
                <el-input v-model="formObject.purchaseGroup"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="验收方式" prop="checkMethod">
                <el-input v-model="formObject.checkMethod"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="项目名称" prop="projectId">
                <el-input v-model="formObject.projectId"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="仓库" prop="warehouseId">
                <el-select
                  v-model="formObject.warehouseId"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in warehouseList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="rowId" :span="8">
              <el-form-item label="变更原因" prop="changeReason">
                <el-input
                  type="textarea"
                  v-model="formObject.changeReason"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="desc-title">财务信息</div>
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="结算币别" prop="settlementCurrency">
                <el-select
                  v-model="formObject.settlementCurrency"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in settlementCurrencyList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="付款条件" prop="termOfPayment">
                <el-input v-model="formObject.termOfPayment"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="结算方式" prop="settlementMethod">
                <el-input v-model="formObject.settlementMethod"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="汇率类型" prop="exchangeRateType">
                <el-input v-model="formObject.exchangeRateType"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="汇率" prop="exchangeRate">
                <el-input v-model="formObject.exchangeRate"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="价目表" prop="priceInfoId">
                <el-input v-model="formObject.priceInfoId"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="折扣表" prop="discountInfoId">
                <el-input v-model="formObject.discountInfoId"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="定价时点" prop="pricingTimePoint">
                <el-date-picker
                  v-model="formObject.pricingTimePoint"
                  type="datetime"
                  placeholder="请选择定价时点日期"
                  style="width: 100%"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="集中结算组织" prop="focusSettlementDept">
                <el-input v-model="formObject.focusSettlementDept"></el-input>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="8">
              <el-form-item label="保证金比例" prop="correspondingOrganization">
                <el-input
                  v-model="formObject.correspondingOrganization"
                ></el-input>
              </el-form-item>
            </el-col> -->
            <el-col :span="8">
              <el-form-item label="整单折扣额" prop="wholeDiscountAmount">
                <el-input v-model="formObject.wholeDiscountAmount"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="税额" prop="taxAmount">
                <el-input v-model="formObject.taxAmount"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="金额" prop="moneyAmount">
                <el-input v-model="formObject.moneyAmount"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="价税合计" prop="totalPriceTax">
                <el-input v-model="formObject.totalPriceTax"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="本位币" prop="totalPriceTaxBase">
                <el-input v-model="formObject.totalPriceTaxBase"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label-width="160px"
                label="累计付款申请费金额"
                prop="totalPaymentApplyAmount"
              >
                <el-input
                  v-model="formObject.totalPaymentApplyAmount"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label-width="160px"
                label="申请单未付款累计金额"
                prop="applyFormUnpaidAmount"
              >
                <el-input v-model="formObject.applyFormUnpaidAmount"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="累计付款金额" prop="groupSupplier">
                <el-input v-model="formObject.groupSupplier"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item
                label-width="160px"
                label="订单未付款金额"
                prop="totalPaymentAmount"
              >
                <el-input v-model="formObject.totalPaymentAmount"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="累计退款金额" prop="totalReturnAmount">
                <el-input v-model="formObject.totalReturnAmount"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="desc-title">供应商信息</div>
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="供货方" prop="providerId">
                <el-input
                  v-model="formObject.orderSupplier.providerId"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="供货方联系人" prop="providerContacts">
                <el-input
                  v-model="formObject.orderSupplier.appproviderContactslyId"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="职务" prop="post">
                <el-input v-model="formObject.orderSupplier.post"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="手机" prop="phone">
                <el-input v-model="formObject.orderSupplier.phone"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="供货方地址" prop="address">
                <el-input v-model="formObject.orderSupplier.address"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="结算方" prop="balanceId">
                <el-input
                  v-model="formObject.orderSupplier.balanceId"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="收款方" prop="receiveId">
                <el-input
                  v-model="formObject.orderSupplier.receiveId"
                ></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="邮箱" prop="email">
                <el-input v-model="formObject.orderSupplier.email"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
        <el-collapse-item title="订单条款" name="orderPurchaseTerms">
          <el-button type="text" @click="addNewRow('orderPurchaseTerms')"
            >新增行</el-button
          >
          <el-table
            :data="formObject.orderPurchaseTerms"
            style="width: 100%"
            highlight-current-row
            border
          >
            <el-table-column label="操作" width="60">
              <template slot-scope="scope">
                <el-button
                  plain
                  icon="el-icon-minus"
                  size="mini"
                  @click="
                    handleDataDelete(
                      scope.$index,
                      scope.row,
                      'orderPurchaseTerms'
                    )
                  "
                ></el-button>
              </template>
            </el-table-column>
            <el-table-column label="条款编码">
              <template slot-scope="scope">
                <el-form-item prop="id" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.id">
                    <i
                      slot="suffix"
                      class="el-input__icon el-icon-notebook-2"
                      style="cursor: pointer"
                      @click="addDialog('termsId', scope.$index)"
                    ></i>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="条款名称" width="150">
              <template slot-scope="scope">
                <el-form-item prop="name" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.name"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="条款类型">
              <template slot-scope="scope">
                <el-form-item prop="sex" label-width="0px" style="margin: 0">
                  <el-select
                    v-model="scope.row.sex"
                    placeholder="请选择"
                    style="width: 100%"
                  >
                    <el-option key="0" label="男" value="0"></el-option>
                    <el-option key="1" label="女" value="1"></el-option>
                    <el-option key="2" label="未知" value="2"></el-option>
                  </el-select>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="条款内容">
              <template slot-scope="scope">
                <el-form-item
                  prop="describe"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.describe"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="描述">
              <template slot-scope="scope">
                <el-form-item
                  prop="workTel"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.workTel" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </el-collapse-item>
        <el-collapse-item title="明细信息" name="orderDetails">
          <el-button type="text" @click="addNewRow('orderDetails')"
            >新增行</el-button
          >
          <el-table
            :data="formObject.orderDetails"
            style="width: 100%"
            highlight-current-row
            @selection-change="handleSelectionChange(orderDetails)"
            border
          >
            <el-table-column label="操作" width="60">
              <template slot-scope="scope">
                <el-button
                  plain
                  icon="el-icon-minus"
                  size="mini"
                  @click="
                    handleDataDelete(scope.$index, scope.row, 'orderDetails')
                  "
                ></el-button>
              </template>
            </el-table-column>
            <el-table-column width="200" label="物料编码">
              <template slot-scope="scope">
                <el-form-item
                  label-width="0px"
                  prop="materialCode"
                  style="margin: 0"
                >
                  <el-input
                    @focus="addDialog('material', scope.$index)"
                    v-model="scope.row.materialCode"
                  >
                    <i
                      slot="suffix"
                      @click="addDialog('material', scope.$index)"
                      class="el-input__icon el-icon-notebook-2"
                      style="cursor: pointer"
                    ></i>
                  </el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <!-- <el-table-column label="物料名称">
              <template slot-scope="scope">
                <el-form-item
                  prop="orderId"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.orderId"></el-input>
                </el-form-item>
              </template>
            </el-table-column> -->
            <!-- <el-table-column label="规格型号">
              <template slot-scope="scope">
                <el-form-item
                  prop="actualPrepaidAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.actualPrepaidAmount"></el-input>
                </el-form-item>
              </template>
            </el-table-column> -->
            <el-table-column width="200" label="采购单位">
              <template slot-scope="scope">
                <el-form-item
                  prop="purchaseUnit"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.purchaseUnit"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" v-if="rowId" label="原采购数量">
              <template slot-scope="scope">
                <el-form-item
                  prop="originalNumber"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    :disabled="true"
                    v-model="scope.row.originalNumber"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="采购数量">
              <template slot-scope="scope">
                <el-form-item prop="number" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.number" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="200" label="交货日期">
              <template slot-scope="scope">
                <el-form-item
                  prop="deliveryDate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-date-picker
                    style="width: 100%"
                    v-model="scope.row.deliveryDate"
                    type="date"
                    placeholder="选择交货日期"
                  >
                  </el-date-picker>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="计价数量">
              <template slot-scope="scope">
                <el-form-item
                  prop="pricingNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.pricingNum" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="单价">
              <template slot-scope="scope">
                <el-form-item prop="price" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.price" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column width="120" v-if="rowId" label="原含税单价">
              <template slot-scope="scope">
                <el-form-item
                  prop="originalContainsTaxPrice"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    :disabled="true"
                    v-model="scope.row.originalContainsTaxPrice"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="含税单价">
              <template slot-scope="scope">
                <el-form-item
                  prop="taxPrice"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.taxPrice" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column width="120" label="折扣率%">
              <template slot-scope="scope">
                <el-form-item
                  prop="discountRate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.discountRate"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="折扣额">
              <template slot-scope="scope">
                <el-form-item
                  prop="discountAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.discountAmount"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="税率%">
              <template slot-scope="scope">
                <el-form-item
                  prop="taxRate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.taxRate" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="税额">
              <template slot-scope="scope">
                <el-form-item
                  prop="taxAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.taxAmount" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="价税合计">
              <template slot-scope="scope">
                <el-form-item
                  prop="totalTaxPrice"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.totalTaxPrice"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="金额">
              <template slot-scope="scope">
                <el-form-item
                  prop="amountMoney"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.amountMoney"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <!-- <el-table-column label="净价">
              <template slot-scope="scope">
                <el-form-item prop="userId" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.userId" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column> -->
            <el-table-column width="200" label="需求组织">
              <template slot-scope="scope">
                <el-form-item
                  prop="requireDept"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.requireDept"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="200" label="收料组织">
              <template slot-scope="scope">
                <el-form-item
                  prop="receivingDept"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.receivingDept"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="60" label="是否赠品">
              <template slot-scope="scope">
                <el-form-item
                  prop="isGiveaway"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-checkbox
                    :disabled="scope.row.isGiveaway"
                    :v-model="scope.row.isGiveaway"
                    clearable
                  ></el-checkbox>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="200" label="备注">
              <template slot-scope="scope">
                <el-form-item prop="remark" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.remark" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="200" label="供应商物料编码">
              <template slot-scope="scope">
                <el-form-item
                  prop="supplierMaterialCode"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.supplierMaterialCode"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="200" label="供应商物料名称">
              <template slot-scope="scope">
                <el-form-item
                  prop="supplierMaterialName"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.supplierMaterialName"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="库存单位">
              <template slot-scope="scope">
                <el-form-item
                  prop="inventoryUnit"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.inventoryUnit"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="库存单位数量">
              <template slot-scope="scope">
                <el-form-item
                  prop="inventoryNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.inventoryNum"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="累计验收金额">
              <template slot-scope="scope">
                <el-form-item
                  prop="totalAcceptanceAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.totalAcceptanceAmount"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="累计验收比例%">
              <template slot-scope="scope">
                <el-form-item
                  prop="totalAcceptanceRate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.totalAcceptanceRate"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="120" label="业务含税成本单价">
              <template slot-scope="scope">
                <el-form-item
                  prop="totalAcceptanceRate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.totalAcceptanceRate"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column width="200" label="批次号">
              <template slot-scope="scope">
                <el-form-item
                  prop="batchNum"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.batchNum" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <!-- <el-table-column label="验收票数量（库存基本）">
              <template slot-scope="scope">
                <el-form-item prop="userId" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.userId" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column> -->
          </el-table>
        </el-collapse-item>
        <el-collapse-item title="付款计划" name="orderPaymentPlans">
          <el-button type="text" @click="addNewRow('orderPaymentPlans')"
            >新增行</el-button
          >
          <el-table
            :data="formObject.orderPaymentPlans"
            style="width: 100%"
            highlight-current-row
            border
          >
            <el-table-column label="操作" width="120">
              <template slot-scope="scope">
                <el-button
                  plain
                  icon="el-icon-minus"
                  size="mini"
                  @click="
                    handleDataDelete(
                      scope.$index,
                      scope.row,
                      'orderPaymentPlans'
                    )
                  "
                ></el-button>
              </template>
            </el-table-column>

            <el-table-column label="采购订单id">
              <template slot-scope="scope">
                <el-form-item
                  prop="orderId"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.orderId"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="实际预付金额">
              <template slot-scope="scope">
                <el-form-item
                  prop="actualPrepaidAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.actualPrepaidAmount"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="应付金额">
              <template slot-scope="scope">
                <el-form-item
                  prop="payableMoney"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.payableMoney"></el-input>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column label="应付比例">
              <template slot-scope="scope">
                <el-form-item
                  prop="payableRate"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.payableRate"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="应付日期">
              <template slot-scope="scope">
                <el-form-item
                  prop="payableTime"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.payableTime"></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="是否预付">
              <template slot-scope="scope">
                <el-form-item
                  prop="isPrepaid"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-checkbox v-model="scope.row.isPrepaid" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="付款关联金额">
              <template slot-scope="scope">
                <el-form-item
                  prop="paymentRelatedAmount"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.paymentRelatedAmount"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="预付单号">
              <template slot-scope="scope">
                <el-form-item
                  prop="prepaidCode"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.prepaidCode"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column label="备注">
              <template slot-scope="scope">
                <el-form-item prop="remark" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.remark" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column label="单次预付额度">
              <template slot-scope="scope">
                <el-form-item
                  prop="singlePrepaidLimit"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input
                    v-model="scope.row.singlePrepaidLimit"
                    clearable
                  ></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="供应商id">
              <template slot-scope="scope">
                <el-form-item
                  prop="supplierId"
                  label-width="0px"
                  style="margin: 0"
                >
                  <el-input v-model="scope.row.supplierId" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="录入人">
              <template slot-scope="scope">
                <el-form-item prop="userId" label-width="0px" style="margin: 0">
                  <el-input v-model="scope.row.userId" clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </el-collapse-item>
      </el-collapse>
    </el-form>
    <el-dialog
      v-if="dialog"
      title="选择"
      :visible.sync="dialog"
      append-to-body
      width="70%"
      destroy-on-close
    >
      <term
        v-if="dialogType === 'termsId'"
        :visible.sync="dialog"
        @getSelectVal="getSelectVal"
      />
      <supplier
        v-else-if="dialogType === 'supplierId'"
        :visible.sync="dialog"
        @getSelectVal="getSelectVal"
      />
      <dept
        v-else-if="dialogType === 'deptId'"
        :visible.sync="dialog"
        @getSelectVal="getSelectVal"
      />
      <procurementContract
        v-else-if="dialogType === 'procurementContract'"
        :visible.sync="dialog"
        @getSelectVal="getSelectVal"
      />
      <material
        v-else-if="dialogType === 'material'"
        :visible.sync="dialog"
        @getSelectVal="getSelectVal"
      />
    </el-dialog>
  </div>
</template>
<script>
import {
  getOrderDetail,
  addList,
  getDocTypeList,
  editList,
} from "@/api/system/purchase";
import { getList } from "@/api/system/warehouse";
import term from "./dialog/term";
import supplier from "./dialog/supplier";
import dept from "./dialog/dept";
import procurementContract from "./dialog/procurementContract";
import material from "./dialog/material";
export default {
  props: ["rowId"],
  components: { term, supplier, dept, procurementContract, material },
  data() {
    return {
      activeName: "basic",
      dialog: false,
      counties: [],
      orgData: [], //创建组织弹窗列表
      orgSelect: [], //选中项
      orgTotal: "", //创建组织弹窗分页
      dialogType: "",
      dialogIndex: "",
      deatilList: [],
      warehouseList: [], //仓库列表
      formObject: {
        originalNumber: "",
        originalContainsTaxPrice: "",
        changeReason: "",
        applyFormUnpaidAmount: "",
        applyId: "",
        applyTime: "",
        baseCurrency: "",
        changeTime: "",
        checkMethod: "",
        closeName: "",
        closeReason: "",
        closeState: "",
        closeTime: "",
        confirmName: "",
        confirmState: "",
        confirmTime: "",
        createId: "",
        createName: "",
        createTime: "",
        discountInfoId: "",
        docBusinessType: "",
        docType: "",
        documentCode: "",
        examineName: "",
        examineTime: "",
        exchangeRate: "",
        exchangeRateType: "",
        focusSettlementDept: "",
        id: "",
        instanceId: "",
        invalidName: "",
        invalidState: "",
        invalidTime: "",
        isExtraPriceTax: true,
        isManualClose: true,
        isTax: true,
        isTemp: true,

        lastUpdateName: "",
        lastUpdateTime: "",
        limit: 0,
        money: "",
        moneyAmount: "",
        moneyAmountBase: "",
        orderDeliveryDetails: [],
        orderDeliverys: [],
        orderDetails: [],
        orderFinanceDetails: [],
        orderNumber: "",
        orderOthers: [],
        orderPaymentExecutions: [],
        orderPaymentPlans: [],
        orderPurchaseTerms: [],
        orderSupplier: {
          balanceId: "",
          changeTime: "",
          createTime: "",
          email: "",
          id: "",

          orderId: "",
          phone: "",
          post: "",
          providerContacts: "",
          providerId: "",
          receiveId: "",
          userId: "",
        },
        page: 0,
        priceInfoId: "",
        pricingTimePoint: "",
        projectId: "",
        purchaseDept: "",
        purchaseGroup: "",
        purchaseOrg: "",
        purchaseOrgLabel: "",
        settlementCurrency: "",
        settlementMethod: "",
        sourceDocType: "",
        state: "",
        status: 0,
        supplierId: "",
        taxAmount: "",
        taxAmountBase: "",
        termOfPayment: "",
        token: "",
        totalPaymentAmount: "",
        totalPaymentApplyAmount: "",
        totalPriceTax: "",
        totalPriceTaxBase: "",
        totalReturnAmount: "",
        updateName: "",
        updateState: "",
        updateTime: "",
        userId: "",
        version: "",
        warehouseId: "",
        wholeDiscountAmount: "",
      },
      documentTypeList: [],
      settlementCurrencyList: [],
      formObjectRules: {
        supplierId: [
          {
            required: true,
            message: "供应商不能为空！",
            trigger: "blur",
          },
        ],
        purchaseOrgLabel: [
          {
            required: true,
            message: "采购组织不能为空！",
            trigger: "blur",
          },
        ],
        docBusinessType: [
          {
            required: true,
            message: "业务类型不能为空！",
            trigger: "blur",
          },
        ],
        docType: [
          {
            required: true,
            message: "单据类型不能为空！",
            trigger: "blur",
          },
        ],
        // applyTime: [
        //     {
        //         required: true,
        //         message: "采购日期不能为空！",
        //         trigger: "blur",
        //     },
        // ],
        // pricingTimePoint: [
        //     {
        //         required: true,
        //         message: "定价时点日期不能为空！",
        //         trigger: "blur",
        //     },
        // ],
        settlementCurrency: [
          {
            required: true,
            message: "币别不能为空！",
            trigger: "blur",
          },
        ],
        warehouseId: [
          {
            required: true,
            message: "仓库不能为空！",
            trigger: "blur",
          },
        ],
        changeReason: [
          {
            required: true,
            message: "变更原因不能为空！",
            trigger: "blur",
          },
        ],
      },
      props: {},
    };
  },
  computed: {
    // docBusinessType() {
    //   this.formObject.docBusinessType = this.formObject.docType;
    //   const item = this.documentTypeList.find(
    //     (e) => e.id === this.formObject.docType
    //   );
    //   if (item) {
    //     return item.title;
    //   } else {
    //     return "";
    //   }
    // },
  },
  methods: {
    // 页签切换事件
    handleClick(tab, event) {},
    // 附件上传
    handleFileChange() {
      console.log("文件上传");
    },

    // 基础表单提交
    submit(cb) {
      this.$refs["formObjectRef"].validate((valid) => {
        if (valid) {
          this.formObject.orderDetails = this.formObject.orderDetails.map(
            (item) => {
              return {
                ...item,
                warehouseId: this.formObject.warehouseId,
              };
            }
          );
          if (this.formObject.docType) {
            this.formObject.docType =
              this.formObject.docType[this.formObject.docType.length - 1];
            this.formObject.docBusinessType =
              this.formObject.docType[this.formObject.docType.length - 1];
          }
          if (this.rowId) {
            this.formObject.parentId = this.formObject.id;
            delete this.formObject.id;
            editList(this.formObject).then((res) => {
              if (res.code === 200) {
                cb();
                this.$message({
                  message: "修改成功！",
                  type: "success",
                });
              }
            });
            return;
          }
          addList(this.formObject).then((res) => {
            if (res.code === 200) {
              cb();
              this.$message({
                message: "新增成功！",
                type: "success",
              });
            }
          });
        }
      });
    },

    // 删除行
    handleDataDelete(index, row, type) {
      this.$confirm("请确认是否要删除此行？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          if (type == "orderDetails") {
            this.formObject.orderDetails.splice(index, 1);
          } else if (type == "orderPaymentPlans") {
            this.formObject.orderPaymentPlans.splice(index, 1);
          } else if (type === "orderPurchaseTerms") {
            this.formObject.orderPurchaseTerms.splice(index, 1);
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    //明细信息添加行
    addOrderDetails(e, type) {
      let obj = {
        amountMoney: "",
        batchNum: "",
        businessTaxCostPrice: "",
        changeTime: "",
        containsTaxPrice: "",
        createTime: "",
        deliveryAddress: "",
        deliveryDate: "",
        deliveryLocation: "",
        discountAmount: "",
        discountRate: "",
        id: "",
        inventoryId: "",
        inventoryNum: 0,
        inventoryUnit: "",
        isGiveaway: "",

        limit: 0,
        materialId: "",
        materialCode: "",
        noTaxMoney: "",
        number: 0,
        page: 0,
        price: "",
        pricingNum: "",
        pricingUnit: "",
        purchaseUnit: "",
        ramarks: "",
        receivedFirstTicketsNum: "",
        receivingDept: "",
        relationId: "",
        requireDept: "",
        settlementDept: "",
        sourceDocCode: "",
        sourceDocType: "",
        sourceRelationId: "",
        supplierMaterialCode: "",
        supplierMaterialName: "",
        taxAmount: "",
        taxMoney: "",
        taxPrice: "",
        taxRate: "",
        token: "",
        totalAcceptanceAmount: "",
        totalAcceptanceRate: "",
        totalTaxPrice: "",
        type: 0,
        warehouseId: "",
        warehouseRegionId: "",
      };

      if (e) {
        if (type === "edit") {
          obj.materialId = e.id;
        }
        // const flag = this.formObject.orderDetails.some(
        //   (item) => item.materialId === e.materialId
        // );
        // if (flag) {
        //   this.$message.warning("选择中有相同项已取最新选择为准");
        //   return;
        // }
        for (const key in obj) {
          if (e[key]) {
            obj[key] = e[key];
          }
        }
      }
      this.formObject.orderDetails.push(obj);
    },

    //订单条款添加行
    addOrderPaymentPlans() {
      let obj = {
        actualPrepaidAmount: "",
        changeTime: "",
        createTime: "",
        id: "",
        isPrepaid: "",

        orderId: "",
        payableMoney: "",
        payableRate: "",
        payableTime: "",
        paymentRelatedAmount: "",
        prepaidCode: "",
        remark: "",
        singlePrepaidLimit: "",
        supplierId: "",
        userId: "",
      };
      this.formObject.orderPaymentPlans.push(obj);
    },

    //付款计划添加行
    addOrderPurchaseTerms() {
      let obj = {
        changeTime: "",
        createTime: "",
        describe: "",
        id: "",

        orderId: "",
        purchaseTermsId: "",
        userId: "",
      };
      this.formObject.orderPurchaseTerms.push(obj);
    },

    //添加新行
    addNewRow(type) {
      if (type === "orderDetails") {
        this.addOrderDetails();
      } else if (type === "orderPaymentPlans") {
        this.addOrderPaymentPlans();
      } else if (type === "orderPurchaseTerms") {
        this.addOrderPurchaseTerms();
      }
    },
    getSelectVal(val) {
      console.log("this.dialogType", this.dialogType, val);
      if (this.dialogType === "termsId") {
        this.formObject.orderPurchaseTerms[this.dialogIndex].id = val[0].id;
        this.formObject.orderPurchaseTerms[this.dialogIndex].sourceRelationId =
          val[0].id;
      } else if (this.dialogType === "supplierId") {
        this.formObject.supplierId = val[0].id;
      } else if (this.dialogType === "deptId") {
        this.formObject.purchaseOrg = val[0].deptId;
        this.formObject.purchaseOrgLabel = val[0].deptName;
      } else if (this.dialogType === "material") {
        if (val.length) {
          this.formObject.orderDetails.splice(this.dialogIndex, 1);
          val.forEach((e) => {
            this.addOrderDetails(e, "edit");
          });
        }
      } else if (this.dialogType === "procurementContract") {
        val.forEach((e) => {
          this.addOrderDetails(e);
        });
      }
    },
    //点击选择dialog中的一条数据回显
    addDialog(type, index) {
      this.dialog = true;
      this.dialogType = type;
      this.dialogIndex = index;
    },
    //获取单据类型
    getDocTypeListApi() {
      getDocTypeList({ parentCode: "All" }).then((res) => {
        if (res.code === 200) {
          this.documentTypeList = res.rows;
        }
      });
    },
    selectKeyCode(val) {
      const index = this.documentTypeList.findIndex(
        (item) => item.docCode === val[0]
      );
      if (index !== -1) {
        getDocTypeList({ parentCode: val[0] }).then((res) => {
          if (res.code === 200) {
            if (!res.rows.length) {
              const documentTypeList = Object.assign(
                {},
                this.documentTypeList[index]
              );
              delete documentTypeList.treeList;
              this.$set(this.documentTypeList, index, {
                ...documentTypeList,
              });
              return;
            }
            this.$set(this.documentTypeList, index, {
              ...this.documentTypeList[index],
              treeList: res.rows,
            });
          }
        });
      }
    },
    //获取币别
    getSettlementCurrency() {
      this.getDicts("king_currency_type").then((res) => {
        this.settlementCurrencyList = res.data.map((item) => {
          return {
            label: item.dictLabel,
            value: item.dictValue,
          };
        });
      });
    },
    //获取仓库
    getWareHouseList() {
      getList().then((res) => {
        if (res.code === 200) {
          this.warehouseList = res.rows.map((item) => {
            return {
              label: item.wareName,
              value: item.id,
            };
          });
        }
      });
    },
    //下拉类型选择
    handleCommand(val) {
      this.dialogType = val;
      this.dialog = true;
      this.activeName = "orderDetails";
    },
  },
  created() {
    console.log("rowId", this.rowId);
    // 查询中国下属省份
    // this.getProvince("20230705392153575054249984");
    this.getDocTypeListApi();
    this.getSettlementCurrency();
    this.getWareHouseList();
    if (this.rowId) {
      getOrderDetail(this.rowId).then((res) => {
        if (res.code === 200) {
          this.formObject = res.data;
          this.formObject.orderDetails.forEach((e) => {
            e.originalNumber = e.number;
            e.originalContainsTaxPrice = e.taxPrice;
          });
        }
      });
    }
    this.props = {
      lazy: true,
      lazyLoad(node, resolve) {
        const { level } = node;
        const parentCode = level >= 1 ? node.value : "All";
        getDocTypeList({ parentCode }).then((res) => {
          if (res.code === 200) {
            this.documentTypeList = res.rows;
            const nodes = res.rows.map((item) => ({
              value: item.docCode,
              label: item.title,
            }));
            // 通过调用resolve将子节点数据返回，通知组件数据加载完成
            resolve(nodes);
          }
        });
      },
    };
  },
};
</script>
<style lang="scss" scoped>
// .add {
//   padding: 15px;
// }
.panel-title {
  font-size: 18px;
  color: #37474f;
  font-weight: 500;
  text-shadow: rgba(0, 0, 0, 0.15) 0 0 1px;
}

::v-deep .el-form-item__content {
  margin-left: 0;
}

.main-responsible {
  font-size: 14px;
  font-weight: 550;
  color: #263238;
  position: relative;
  text-indent: 15px;
}
</style>
